package com.tan.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class MovementsadminVo implements Serializable {

    private String id; //动态id
    private Long userId; //用户id
    private String avatar; //头像
    private String nickname; //昵称
    private String textContent; //文字动态
    private String[] imageContent; //图片动态
    private Integer createDate; //发布时间 如: 10分钟前
    private Integer likeCount; //点赞数
    private Integer commentCount; //评论数
    private Integer state;//动态状态

    public static MovementsadminVo init(MovementsVo movementsVo) {
        MovementsadminVo movementsadminVo = new MovementsadminVo();
        movementsadminVo.setId(movementsVo.getId());
        movementsadminVo.setUserId(movementsVo.getUserId());
        movementsadminVo.setAvatar(movementsVo.getAvatar());
        movementsadminVo.setNickname(movementsVo.getNickname());

        movementsadminVo.setTextContent(movementsVo.getTextContent());
        movementsadminVo.setImageContent(movementsVo.getImageContent());

        // 解析并转换 createDate 为时间戳
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = sdf.parse(movementsVo.getCreateDate());
            movementsadminVo.setCreateDate((int) (date.getTime() / 1000)); // 转换为秒级时间戳
        } catch (Exception e) {
            // 处理日期解析异常
            e.printStackTrace();
            movementsadminVo.setCreateDate(0); // 设置默认值或抛出异常
        }

        movementsadminVo.setLikeCount(movementsVo.getLikeCount());
        movementsadminVo.setCommentCount(movementsVo.getCommentCount());

        movementsadminVo.setState(movementsVo.getState());
        return movementsadminVo;
    }

}
